home *** CD-ROM | disk | FTP | other *** search
- Path: noc.tor.hookup.net!news
- From: Richard Steadman <rsteadma@micromedia.on.ca>
- Newsgroups: comp.lang.c
- Subject: Q: Pointer to an allocated array of structures
- Date: Mon, 18 Mar 1996 15:44:24 -0500
- Organization: Micromedia
- Message-ID: <314DCB28.4385@micromedia.on.ca>
- NNTP-Posting-Host: keeper.mmltd.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Hello. I have a bit of code which runs ok, but lint (lclint)
- complains about it. I was wondering if I was using pointers
- the correct way, or if I was stretching the rules a bit.
-
- A structure is typedef'ed as follows:
-
- typedef struct {
- long a;
- long b;
- } S;
-
- Then I declare a pointer to this type:
-
- S *pointer;
-
- and use malloc() to get space for it:
-
- pointer=malloc(1000 * sizeof(S));
-
- Then I can reference the array the usual way:
-
- pointer[index].a = some_long;
-
- This seems to run ok, but produces various error messages from
- lclint when I'm using the array:
-
- >program.c:87,8: Passed storage *pointer contains 2 undefined fields:
- >a, b. Storage derivable from a parameter, return value or
- >global is not defined. Use /*@out@*/ to denote passed or returned
- >storage which need not be defined. Use -compdef to suppress message. [when passing "pointer" to a function: func(pointer);]
-
- >program.c:90,13: Field pointer[].b used before definition
- >An rvalue is used that may not be initialized to a value on some
- >execution path. Use -usedef to suppress message. [when using a variable as the array index: index[i].a=var; ]
-
- >program.c:113,26: Unqualified storage passed as only: realloc
- >(pointer,...). Unqualified storage is transferred in an inconsistent
- >way. Use -unqualifiedtrans to suppress message.
- > cvrsort.c:63,8: Storage index becomes unqualified [when reallocating]
-
- I have also tried declaring the pointer as:
- S (*pointer)[];
-
- but this doesn't seem to help. I don't know if one of these
- pointer declarations is wrong, or whether one is preferable.
- The first method seems to work at least, though there seems
- to be some problems when passing the pointer to a function
- which uses it as an array.
-
- Basically, I just want to know the right way to declare an
- array of structures which will use allocated space, without
- using pointers to the individual structures (no arrays of
- pointers).
-
- Thanks.
-
- Richard Steadman
- rsteadma@mmltd.com
-